package com.yiming.shiro.repository;

import com.yiming.shiro.repository.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RoleRepository extends JpaRepository<Role, Long> {

    @Query(value = "select r from Role r where r.active = true and r.roleId in (select ur.roleId from UserRole ur left join User u on ur.userId = u.userId and u.name = :userName)")
    List<Role> findRoleByUserName(@Param("userName") String userName);
}
